#include <iostream>
#include <map>
#include <deque>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>

using namespace std;

#define oo 1000000000

vector<int> node[250000];
int trace[250000], dep[250000];
int earliest[100];

int id(int c, int t)
{
	return c*2400 + t;
}

struct stop {
	int Time, city;
	stop(int t, int c)
	{
		Time = t;
		city = c;
	}
};

int nCity, nTrain;
map<string, int> city;
vector< vector<stop> > train;

vector<int> Time[100];
int startTime;
int start, end;
string sn, en;

void input()
{
	cin >> nCity;
	city.clear();
	for (int i = 0; i < nCity; i++) 
	{
		string name;
		cin >> name;
		city[name] = i;

		Time[i].clear();
	}

	cin >> nTrain;
	train.clear();
	for (int i = 0; i < nTrain; i++) 
	{
		int nStops;
		cin >> nStops;
		vector<stop> vs;
		for (int j = 0; j < nStops; j++)
		{
			int t;
			string c;
			cin >> t >> c;
			vs.push_back(stop(t, city[c]));

			Time[city[c]].push_back(t);
		}
		train.push_back(vs);
	}

	cin >> startTime >> sn >> en;
	start = city[sn];
	end = city[en];

	for (int i = 0; i < (int) Time[start].size(); i++) 
		if (startTime == Time[start][i]) return;
		
	Time[start].push_back(startTime);
}

void init()
{
	for (int i = 0; i < 250000; i++) node[i].clear();

	cerr << "within city" << endl;
	for (int i = 0; i < nCity; i++) 
	{
		sort(Time[i].begin(), Time[i].end());

		for (int j = 0; j < (int) Time[i].size()-1; j++)
		{
			node[id(i, Time[i][j])].push_back(id(i, Time[i][j+1]));
			cerr << i << " " << Time[i][j] << " --> " << i << " " << Time[i][j+1] << endl;
		}
	}

	cerr << "within path" << endl;
	for (int i = 0; i < nTrain; i++) 
	{
		for (int j = 0; j < (int) train[i].size()-1; j++) 
		{
			node[id(train[i][j].city, train[i][j].Time)].push_back(id(train[i][j+1].city, train[i][j+1].Time));
			cerr << train[i][j].city << " " << train[i][j].Time << " --> " << train[i][j+1].city << " " << train[i][j+1].Time << endl;
		}
	}

	memset(trace, -1, sizeof(trace));
	for (int i = 0; i < nCity; i++) earliest[i] = oo;
	earliest[start] = startTime;


	for (int i = 0; i < (int) Time[start].size(); i++)
	{
		dep[id(start, Time[start][i])] = Time[start][i];
		trace[id(start, Time[start][i])] = id(start, Time[start][i]);
	}

}

void process()
{
	init();
	deque<int> q;
	q.push_back(id(start, startTime));

	while (!q.empty())
	{
		int u = q.front();
		q.pop_front();

		cerr << "from " << u/2400 << " " << u%2400 << endl;
		
		for (int i = 0; i < (int) node[u].size(); i++)
		{
			int v = node[u][i];
			cerr << "to" << v/2400 << " " << v%2400 << endl;
			int cityv = v / 2400;
			int Timev = v % 2400;

			if (trace[v] == -1 || earliest[cityv] > Timev || (earliest[cityv] == Timev && dep[v] < dep[u]))
			{
				earliest[cityv] = Timev;
				trace[v] = u;
				dep[v] = dep[u];
				cerr << "trace of " << v << " is " << u << endl;
			}

			q.push_back(v);
		}
	}
}

int traceBack(int v)
{
	cerr << v/2400 << " " << v%2400 << endl;

	int u = trace[v];
	if (dep[u] == u%2400)
	{
		return u%2400;
	}
	else return traceBack(u);
}

void output(int test)
{
	cout << "Scenario " << test << endl;

	cerr << earliest[end] << endl;
	
	if (earliest[end] == oo) cout << "No connection" << endl;
	else
	{
		int t1 = traceBack(id(end, earliest[end]));
		cout << "Departure ";
		if (t1 < 1000) cout << 0;
		if (t1 < 100) cout << 0;
		if (t1 < 10) cout << 0;
		cout << t1;
		cout << " " << sn << endl;

		cout << "Arrival   " << earliest[end] << " " << en << endl;
	}
}

int main()
{
	int ntest;
	cin >> ntest;
	for (int test = 1; test <= ntest; test++)
	{

		input();
		process();
		output(test);

	}
	return 0;
}

